package engine.newUi
{
	import engine.control.loading.MultLoader;
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.Record;
	import engine.data.ResPath;
	import engine.event.SoundEvent;
	import engine.flag.ResourcesPath;
	import engine.logic.LogSendLogic;
	import engine.logic.McPool;
	import engine.logic.login.PlayCDTimerLogic;
	import engine.net.datatype.WString;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.tip.TipsMainLogic;
	import engine.ui.AlertUI;
	import engine.ui.MsgTipsLogic;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import newx.StageInfo;
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.window.NxWindowEvent;
	import newx.com.loader.SwfLoader;
	import newx.utils.FilterUtil;

	/**
	 * 江湖—产业
	 * @author zhouqiang
	 * 
	 */	
	public class IndustryLogic
	{
		/***/
		public static var _self:IndustryLogic; 
		
		/***/
		public var _ui:IndustryUI;
		
		/***/
		private var _model:ModelLocator;
		
		/***/
		private var _bind:BindManage;
		
		/**绑定index*/
		private var _bindIndex:int	=	-1;
		
		/**绑定index*/
		private var _bindThingsIndex:int	=	-1;
		
		/**绑定VIP index*/
		private var _bindVIPIndex:int	=	-1;
		
		/**伙伴表格数组*/
		private var _partnerArr:Array;
		
		/**产业index*/
		private var _type:int	=	0;
		
		/**货物的个数*/
		private var _goodsNum:int	=	2;
		
		/**所有产业信息*/
		private var allInfoArr:Array;
		
		/**管家状态*/
		private var _employStatus:int	=	-1;
		
		/**好友名字*/
		private var _friendName:String;
		
		/**每条信息的长度*/
		private var _dataLength:int	=	9;
		
		/**单个产业信息*/
		private var _infoObj:Object;
		
		/**CD时间*/
		private var _CDTime:Number;
		
		/**cd计时器*/
		private var _timer:Timer;
		
		private var _BaseIncome:Number;
		
		/**产业等级段（客栈，赌坊，青楼）*/
		private var _IndusLevel:int;
		
		/**产业实际等级*/
		private var _InfoLevel:int;
		
		private var _serverTime:int;
		
		private var _NowCDTime:int;
		
		private var _nexExpend:int;
		
		/**当前倍率*/
		private var _multiLv:int;
		
		private var _effectMc:MovieClip;
		
		/**倍率数组（读配置文件）*/
		private var _multiLvArr:Array;
		
		/**产业等级数组（读配置文件）*/
		private var _levelArr:Array;
		
		/**基础奖励（和等级有关读配置文件）*/
		private var _BaseIncomeArr:Array;
		
		private var _roleLev:int;
		
		/**鼠标是否放在购买按钮上*/
		private var _isMouseOver:Boolean	=	false;
		
		/**是否显示刷新消耗tips*/
		private var _isShowTips:Boolean	=	false;
		
		/**当前购买剩余次数*/
		private var _lastCount:int;
		
		private var houseSwf:MovieClip;
		public function IndustryLogic()
		{
		}
		
		public function get ui():IndustryUI
		{
			if(_ui==null)
			{
				_ui	=	new IndustryUI();
			}
			return _ui
		}
		/**
		 * 得到产业信息
		 * @param type
		 * @param obj
		 * @param CDtime
		 * 
		 */		
	
		public static function getInstance():IndustryLogic
		{
			if(_self == null)
			{
				_self = new IndustryLogic()
			}
			return _self;
		}
		
		public function Init():void
		{
			_partnerArr	=	[];
			allInfoArr	=	[];
			_bind		=	BindManage.getInstance();
			_model		=	ModelLocator.getInstance();		
			_multiLvArr	=	[];
			_levelArr	=	[];
			_timer		=	new Timer(1000);
			_timer.addEventListener(TimerEvent.TIMER, timerHandle);
			//账单恢复时间
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_PRODUCTION_UPDATE_GOODS),CDtimeHandle);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_SENDSERVERTIME),getServerTime);
			_model.addEventListener(
				String(CustomToClientFlag.SERVER_CUSTOMMSG_PRODUCTION_GET_INFO),getTravel);	
		}
		
		private function loadHouse():void
		{
			if(houseSwf == null)
			{
				var mc:MovieClip = MultLoader.getInstance().getSourceByUrl(ResPath.SWF + "IndustryHouse.swf") as MovieClip;
				ui.houseClip.source	=	mc;
				houseSwf			=	mc;
				groupInit();
//				SwfLoader.StartLoad(StageInfo.swfResPath + "IndustryHouse.swf",null,loadChessboardFun);
			}
			else
			{
				beforeshowInfo();
			}
		}
		
		private function loadChessboardFun(mc:MovieClip,pL:Array):void
		{
			ui.houseClip.source	=	mc;
			houseSwf			=	mc;
			groupInit();
		}
		
		public function BeforeShow():void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_PRODUCTION_GET_INFO);
			loadHouse();
		}
		
		private function beforeshowInfo():void
		{
			addEvent();
			_effectMc	=	McPool.borrowRes( "upgrade" );
			_effectMc.x	=	ui.houseClip.x;
			_effectMc.y	=	ui.houseClip.y;
			_effectMc.gotoAndStop(1);
			ui.upEffect.visible		=	false;
			ui.houseEffect.visible	=	false;
//			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_PRODUCTION_GET_INFO);
			var levelStr:String	=	StaticIni.getIniVar("IndustryExpConfig","level");
			var typeStr:String	=	StaticIni.getIniVar("IndustryExpConfig","type");
			var Arrstr:String	=	StaticIni.getIniVar("IndustryExpConfig","arr");
			_levelArr		=	levelStr.split(",");
			_multiLvArr	=	typeStr.split(",");
			_BaseIncomeArr	=	Arrstr.split(",");
			_roleLev		=	_model.scene.roleLevel;
			
			var vipLevel:int	=	_model.scene.Role.getVipLevel();
			ui.vipBtn.visible	=	false;
			
			if(vipLevel >= 5)
			{
				ui.vipBtn.visible	=	true;
			}
			if(_bindThingsIndex == -1)
			{
				_bindThingsIndex	=	_bind.BindProp(_model.scene.Role,"ProductionCurGoods",this,"travelCount");	
			}
			
			if(_bindIndex == -1)
			{
				_bindIndex	=	_bind.BindProp(_model.scene.Role,"MultiLvUpCounter",this,"MultiLvChange");	
			}
			
			if(_bindVIPIndex == -1)
			{
				_bindVIPIndex	=	_bind.BindRecord(_model.scene,"VIPCountRec",changeInfoFun,removeFun);
			}
		}
		private function changeInfoFun(PropertiesName:String,PropertiesValue:Array,data:*):void
		{
			if(int(PropertiesName) == 10)
			{
				_lastCount	=	PropertiesValue[2]-PropertiesValue[1];
			}
			adddbtnOverHandle();
		}
		
		private function removeFun(PropertiesName:String,PropertiesValue:Array,data:*):void
		{
			
		}
		
		public function AfterHide():void
		{
			removeEvent();
		}
		
		public function set travelCount(val:int):void
		{
			_goodsNum	=	val;
			ui.goodsLab.htmlText	=	StaticIni.getSwfLangStrVar("UIString_1000210",[val]);	
		}
		
		/**
		 * 绑定刷新次数 
		 * @param val
		 * 
		 */		
		public function set MultiLvChange(val:int):void
		{
			onshuaxinOverhandle();
		}
		
		/**
		 * 初始化倍率图片 
		 * 
		 */		
		private function groupInit():void
		{
			var mc:MovieClip;
			for(var i:int = 0; i < 5;i++)
			{
				mc	= ui.itemGroup.getItemByIndex(i);
				var clip:NxClip	=	new NxClip();
				clip.x	=	5;
				clip.y	=	5;		
				clip.source		=	ResPath.PNG + "Money_"+String(i)+".png";
				clip.filters	=	[FilterUtil.GrayColorFilter];
				mc.addChild(clip);
				_partnerArr.push(clip);
				mc["index"]		=	i;
				mc.addEventListener(MouseEvent.ROLL_OVER,onGroupOverHandle)
				mc.addEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			}
			ui.itemGroup.addChild(ui.effect);
			ui.effect.gotoAndPlay(1)
			ui.itemGroup.addChild(ui.upEffect);
			beforeshowInfo();
		}
		
		private function timerHandle(e:TimerEvent):void
		{
			_CDTime--;
			if(_CDTime <= 0)
			{
				ui.timeLab.htmlText	 =		"";
				_timer.stop();
				if(!ui.created || _goodsNum >= 8) return;
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_PRODUCTION_GET_INFO);
			}
			else
			{
				ui.timeLab.htmlText	 =	StaticIni.getSwfLangStrVar("UIString_1000217",
										 [PlayCDTimerLogic.getInstance().getTimerStr(_CDTime,true)]);
			}
			
		}
		
		
		/**
		 * 产业收益百分比
		 * @param e
		 * 
		 */		
		private function getIndustryInfo(e:CustomMsgEvent):void
		{
			var arr:Array		=	e.pList;
			if(_multiLv < arr[1]-1)
			{
				ui.upEffect.visible	=	true;
				ui.upEffect.gotoAndPlay(1);
				ui.upEffect.addFrameScript(ui.upEffect.totalFrames - 1,mcOverHandle);
				ui.upEffect.x	=	(_partnerArr[arr[1]-1] as NxClip).parent.x-15;
				ui.upEffect.y	=	(_partnerArr[arr[1]-1] as NxClip).parent.y-13;
			}
			_multiLv			=	arr[1]-1;
			for(var i:int = 0; i < 5;i++)
			{
				(_partnerArr[i] as NxClip).filters	=	[FilterUtil.GrayColorFilter];
			}
			(_partnerArr[arr[1]-1] as NxClip).filters	=	[];
			ui.effect.x	=	(_partnerArr[arr[1]-1] as NxClip).parent.x-12;
			ui.effect.y	=	(_partnerArr[arr[1]-1] as NxClip).parent.y-9;
			
			var str:String		=	StaticIni.getSwfLangStr("UIString_"+String(1000204+arr[1]-1));
			ui.txt1.htmlText	=	StaticIni.getSwfLangStr("UIString_1000213")+str;
			ui.txt2.htmlText	=	StaticIni.getSwfLangStrVar("UIString_1000268",[arr[2]]);
		}
		
		/**
		 * 特效播完后执行函数 
		 * 
		 */		
		private function mcOverHandle():void
		{
			ui.upEffect.stop();
			ui.upEffect.visible	=	false;
		}
		
		/**
		 * 房子升级特效播完后执行函数 
		 * 
		 */		
		private function houseUPOverHandle():void
		{
			ui.houseEffect.stop();
			ui.houseEffect.visible	=	false;
		}
		
		/**
		 * 产业信息(打开界面时收到)
		 * @param e
		 * 
		 */		
		private function getTravel(e:CustomMsgEvent):void
		{
			ui.effect.gotoAndPlay(1);
			var arr:Array		=	e.pList;
			var roleVIPLeve:int	=	_model.scene.Role.GetProperties("VIPLevel");
			_InfoLevel	=	arr[1];
			_IndusLevel	=	(arr[1] - 1) / 10 + 1;
			(_partnerArr[arr[2]-1] as NxClip).filters	=	[];
			ui.effect.x	=	(_partnerArr[arr[2]-1] as NxClip).parent.x-12;
			ui.effect.y	=	(_partnerArr[arr[2]-1] as NxClip).parent.y-9;
			ui.effect.visible = true;
			var str:String	=	StaticIni.getSwfLangStr("UIString_"+String(1000204+arr[2]-1));
			ui.txt1.htmlText	=	StaticIni.getSwfLangStr("UIString_1000213")+str;
			ui.txt2.htmlText	=	StaticIni.getSwfLangStrVar("UIString_1000268",[arr[3]]);
			ui.LevelLab.htmlText= StaticIni.getSwfLangStrVar("UIString_"+(1000550+_IndusLevel),[( arr[1]- (_IndusLevel -1) * 10 )])
			_multiLv	=	arr[2]-1;
			ui.upBtn.visible	= true;
			if(arr[1] >= 30 || roleVIPLeve < 0)
			{
				ui.upBtn.visible	= false;
			}
			
			(ui.houseClip.content as MovieClip).gotoAndStop(_IndusLevel);	
			ui.houseClip.visible = true;
		}
		
		/**
		 * 产业生意 
		 * @param e
		 * 
		 */		
		private function upIndusBusi(e:CustomMsgEvent):void
		{
			var arr:Array		=	e.pList;
		}
		
		/**
		 * 升级产业 
		 * @param e
		 * 
		 */		
		private function upIndustryHandle(e:CustomMsgEvent):void
		{
			var arr:Array		=	e.pList;
			var	factor:Number	=	0.05;
			_InfoLevel			=	arr[1];
			_IndusLevel			=	(arr[1]-1) / 10 + 1;
			var level:int		=	arr[1] % 10;
			ui.LevelLab.htmlText=	 StaticIni.getSwfLangStrVar("UIString_"+(1000550+_IndusLevel),[( arr[1]- (_IndusLevel -1) * 10 )]);		
			ui.houseEffect.gotoAndPlay(1);
			ui.houseEffect.visible	=	true;
			ui.houseEffect.addFrameScript(ui.houseEffect.totalFrames - 1,houseUPOverHandle);
			
			if(arr[1] >= 30)
			{
				ui.upBtn.visible	= false;
			}
			(ui.houseClip.content as MovieClip).gotoAndStop(_IndusLevel);
			ui.txt2.htmlText	=	StaticIni.getSwfLangStrVar("UIString_1000268",[countGetMoney(_multiLv)]);
		}
		
		/**
		 * 产业收获信息 
		 * @param e
		 * 
		 */		
		private function onGetThings(e:CustomMsgEvent):void
		{
			_multiLv	=	0;
			for(var i:int = 0; i < 5;i++)
			{
				(_partnerArr[i] as NxClip).filters	=	[FilterUtil.GrayColorFilter];
			}
			(_partnerArr[0] as NxClip).filters	=	[];
			ui.effect.x	=	(_partnerArr[0] as NxClip).parent.x-12
			ui.effect.y	=	(_partnerArr[0] as NxClip).parent.y-9
			ui.txt1.htmlText	=	StaticIni.getSwfLangStr("UIString_1000213")
										+StaticIni.getSwfLangStr("UIString_1000204");
		}
				
		
		/**
		 * 草药回复时间
		 * @param e
		 * 
		 */		
		private function CDtimeHandle(e:CustomMsgEvent):void
		{	
			_NowCDTime	=	e.pList[1];
			_nexExpend	=	e.pList[2];
			if(e.pList[0] >= 8) return;
			adddbtnOverHandle();
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_QUERYSERVERTIME);
		}
		
		private function getServerTime(e:CustomMsgEvent):void
		{
			_serverTime		=	e.pList[0];
			_CDTime			=	_NowCDTime-_serverTime;
			_timer.start();
		}
		
		/**
		 * 升级产业按钮点击 
		 * @param e
		 * 
		 */		
		private function onUplistHandle(e:MouseEvent):void
		{
			var	yesBtnT		:String			=	StaticIni.getSwfLangStr("SellUI_Sure");
			var	noBtn		:String			=	StaticIni.getSwfLangStr("AlertEx_1");
			var str			:String;
			str	=	StaticIni.getSwfLangStrVar("UIString_1000256",needMoney());
			AlertUI.showAlertEx("",str,[yesBtnT,noBtn],AlertUI.YES|AlertUI.NO,clickClearCD);
			function clickClearCD( type:int, str:String, clickData:* ):void
			{
				if(AlertUI.YES == type )
				{
					SystemSender.getInstance().CustomMsgEx(
						CustomToServerFlag.CLIENT_CUSTOMMSG_PRODUCTION_LV_UP,[_type]);
				}
			}
			LogSendLogic.getInstance().btnClickNumSend(22817);
		}
		
		/**
		 *升级需要消耗的钱 
		 * 
		 */		
		private function needMoney():Array
		{
			var count:int;//花费元宝
			var next:String;//升级收益提高多少；
			if( _InfoLevel > 0 && _InfoLevel < 5 )
			{
				count	=	20 * _InfoLevel;
			}
			else if( _InfoLevel >= 5 && _InfoLevel < 10 )
			{
				count = 100;
			}else if( _InfoLevel >= 10 && _InfoLevel < 20 )
			{
				count = 150 + (_InfoLevel -10) * 50 ;
			}else if( _InfoLevel >= 20 && _InfoLevel < 30 )
			{
				count = 1200;
			}
			
			if( _InfoLevel > 0 && _InfoLevel <= 20 )
			{
				next	=	"5";
			}else if( _InfoLevel > 20 )
			{
				next	=	"10";
			}
			return [count,next];
		}
		
		/**
		 * 增加货物点击事件 
		 * @param e
		 * 
		 */		
		private function onAddgoodshandle(e:MouseEvent):void
		{
			if(_lastCount <= 0){
				NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("UIString_1000673"));
			} else {
				SystemSender.getInstance().CustomMsg(
					CustomToServerFlag.CLIENT_CUSTOMMSG_PRODUCTION_BUY_GOODS);
				LogSendLogic.getInstance().btnClickNumSend(22814);
			}
		}
		
		
		/**
		 * vip按钮点击 
		 * @param e
		 * 
		 */		
		private function onVipClickHandle(e:MouseEvent):void
		{
			SystemSender.getInstance().CustomMsg(
				CustomToServerFlag.CLIENT_CUSTOMMSG_PRODUCTION_VIP_BUY_MULTI_LV,0);
			LogSendLogic.getInstance().btnClickNumSend(22816);
		}
		/**
		 * 显示tips
		 * @param e
		 * 
		 */		
		private function onGroupOverHandle(e:MouseEvent):void
		{
			var index:int	=	(e.currentTarget as MovieClip)["index"];
			var str:String	=	StaticIni.getSwfLangStrVar("UIString_"+String(1000218+index),[countGetMoney(index)]);
			TipsMainLogic.instance.showString(str);
		}
		
		/**
		 * 计算现在可以得到的钱 
		 * 
		 */		
		private function countGetMoney(index:int):Number
		{
			var factor:Number	=	0.05;
			var inCome:int;
			var baseMoney:int	=	int(_BaseIncomeArr[_roleLev-55]);
			if( _InfoLevel >= 20 )
			{
				inCome	=	Math.floor(  baseMoney*(1+Number(_multiLvArr[index]))*(1+(20 - 1)*0.05+(_InfoLevel - 20)*0.1));	
			}
			else
			{
				inCome	=	Math.floor(  baseMoney*(1+Number(_multiLvArr[index]))*(1+0.05*(_InfoLevel - 1)));
			}
			
			return inCome
		}
		/**
		 * 武学显示tips
		 * @param e
		 * 
		 */		
		private function onBookOverHandle(e:MouseEvent):void
		{
			var str:String	=	StaticIni.getSwfLangStr("UIString_1000267");
			TipsMainLogic.instance.showString(str);
		}
		
		
		/**
		 * VIP tips
		 * @param e
		 * 
		 */		
		private function onVIPOverHandle(e:MouseEvent):void
		{
			var str:String	=	StaticIni.getSwfLangStr("UIString_1000280");
			TipsMainLogic.instance.showString(str);
		}
		/**
		 * 刷新tips
		 * @param e
		 * 
		 */		
		private function onshuaxinOverhandle(e:MouseEvent=null):void
		{
			if(e != null)
			{
				_isShowTips	=	true;
			}
			if(_isShowTips == false)return 
			var num:int		=	_model.scene.Role.GetProperties("MultiLvUpCounter");
			var money:int;	
			if(num < 10)
			{
				money	=	(num+1)*2;
			}
			else
			{
				money	=	20
			}
			var str:String	=	StaticIni.getSwfLangStrVar("UIString_1000258",[money]);
			TipsMainLogic.instance.showString(str);
		}
		/**
		 * 武学显示tips
		 * @param e
		 * 
		 */		
		private function adddbtnOverHandle(e:MouseEvent = null):void
		{
			if(e != null)
			{
				_isMouseOver	=	true;
			}
			if(_isMouseOver == false)return 
			var str:String	=	StaticIni.getSwfLangStrVar("UIString_1000257",[_nexExpend,_lastCount]);
			TipsMainLogic.instance.showString(str);
		}
		
		/**
		 * 升级按钮Tips 
		 * @param e
		 * 
		 */		
		private function upBtnOverHandle(e:MouseEvent):void
		{
			var str:String;	
			if(_IndusLevel < 30)
			{
				str =	StaticIni.getSwfLangStr("UIString_1000269");
			}
			else
			{
				str	=	StaticIni.getSwfLangStr("UIString_1000270");
			}
			TipsMainLogic.instance.showString(str);
		}
		/**
		 * 关闭tips
		 * @param e
		 * 
		 */		
		private function onCloseTipsHandle(e:MouseEvent):void
		{
			_isShowTips 	= 	false;
			_isMouseOver	=	false;
			TipsMainLogic.instance.hide();
		}
		
		/**
		 * 根据伙伴的名字返回伙伴的头像ID 
		 * @param name
		 * 
		 */		
		private function getpartnerID(name:String):String
		{
			var friend:Record	= 	_model.scene.GetRecordEx("Friend");
			var	arr:Array		=	friend.recArr;
			for( var i:int = 0; i < arr.length;i++ )
			{
				for( var j:int = 0; j < (arr[i] as Array).length;j++ )
				{
					if(name == arr[i][j])
					{
						return arr[i][10]
					}
				}
			}
			return "22011100";
		}
		/**
		 * 聘请NPC按钮点击事件
		 * @param e
		 * 
		 */		
		private function OnemployClickHandle(e:MouseEvent):void
		{
			ui.headClip.source		=	ResourcesPath.getMiniHeadPic(22011100);
			_employStatus			=	1;
		}
			
		/**
		 * 开始
		 * @param e
		 * 
		 */		
		private function onBeginClickHandle(e:MouseEvent):void
		{
			var str:WString		=	new WString("");
			var partnerID:int	=	220112;	
			var type:int;
			if(_employStatus == 0)
			{
				str		=	WString.toWString(_friendName);
				partnerID=	int(getpartnerID(_friendName));
			}
			SystemSender.getInstance().CustomMsgEx(
				CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_PRODUCTION_AUTO_WORK,[_type,str,partnerID,_employStatus]);
		}
		
		/**
		 * 添加侦听事件 
		 * 
		 */		
		private function addEvent():void
		{
			ui.upBtn.addEventListener(MouseEvent.CLICK,onUplistHandle);
			ui.upBtn.addEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			ui.upBtn.addEventListener(MouseEvent.ROLL_OVER,upBtnOverHandle);	
			
			ui.addbtn.addEventListener(MouseEvent.CLICK, onAddgoodshandle);
			ui.addbtn.addEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			ui.addbtn.addEventListener(MouseEvent.ROLL_OVER,adddbtnOverHandle);
			
			ui.windowBG.addEventListener( NxWindowEvent.WINDOW_CLOSE,onClickClose);
			ui.resultsBtn.addEventListener(MouseEvent.CLICK,onResultBtnClick)
				
			ui.shuaxin.addEventListener(MouseEvent.CLICK,onshuaxinhandle);	
			ui.shuaxin.addEventListener(MouseEvent.ROLL_OVER,onshuaxinOverhandle);
			ui.shuaxin.addEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			
			ui.back2.addEventListener(MouseEvent.ROLL_OVER,onBookOverHandle);
			ui.back2.addEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			
			ui.vipBtn.addEventListener(MouseEvent.CLICK,onVipClickHandle);
			ui.vipBtn.addEventListener(MouseEvent.ROLL_OVER,onVIPOverHandle);
			ui.vipBtn.addEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			
			_model.addEventListener(
				String(CustomToClientFlag.SERVER_CUSTOMMSG_PRODUCTION_UPDATE_MULTI_LV),getIndustryInfo);			
			_model.addEventListener(
				String(CustomToClientFlag.SERVER_CUSTOMMSG_PRODUCTION_GAIN),onGetThings);
			_model.addEventListener(
				String(CustomToClientFlag.SERVER_CUSTOMMSG_PRODUCTION_LV_UP),upIndustryHandle);	
//			_model.addEventListener(
//				String(CustomToClientFlag.SERVER_CUSTOMMSG_PRODUCTION_GET_INFO),getTravel);	
		}
		
		/**
		 * 删除侦听 
		 * 
		 */		
		private function removeEvent():void
		{
			
			ui.upBtn.removeEventListener(MouseEvent.CLICK,onUplistHandle);
			ui.upBtn.removeEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			ui.upBtn.removeEventListener(MouseEvent.ROLL_OVER,upBtnOverHandle);	
			
			ui.addbtn.removeEventListener(MouseEvent.CLICK, onAddgoodshandle);
			ui.addbtn.removeEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			ui.addbtn.removeEventListener(MouseEvent.ROLL_OVER,adddbtnOverHandle);
			
			ui.windowBG.removeEventListener( NxWindowEvent.WINDOW_CLOSE,onClickClose);
			ui.resultsBtn.removeEventListener(MouseEvent.CLICK,onResultBtnClick)
			
			ui.shuaxin.removeEventListener(MouseEvent.CLICK,onshuaxinhandle);	
			ui.shuaxin.removeEventListener(MouseEvent.ROLL_OVER,onshuaxinOverhandle);
			ui.shuaxin.removeEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			
			ui.back2.removeEventListener(MouseEvent.ROLL_OVER,onBookOverHandle);
			ui.back2.removeEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			
			ui.vipBtn.removeEventListener(MouseEvent.CLICK,onVipClickHandle);
			ui.vipBtn.removeEventListener(MouseEvent.ROLL_OVER,onVIPOverHandle);
			ui.vipBtn.removeEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			
			_model.removeEventListener(
				String(CustomToClientFlag.SERVER_CUSTOMMSG_PRODUCTION_UPDATE_MULTI_LV),getIndustryInfo);			
			_model.removeEventListener(
				String(CustomToClientFlag.SERVER_CUSTOMMSG_PRODUCTION_GAIN),onGetThings);
			_model.removeEventListener(
				String(CustomToClientFlag.SERVER_CUSTOMMSG_PRODUCTION_LV_UP),upIndustryHandle);	
//			_model.removeEventListener(
//				String(CustomToClientFlag.SERVER_CUSTOMMSG_PRODUCTION_GET_INFO),getTravel);
		}
		/**
		 * 产业收获 
		 * @param e
		 * 
		 */		
		private function onResultBtnClick(e:MouseEvent):void
		{
			if(_goodsNum > 0)
			{
				ui.txt2.htmlText	=	StaticIni.getSwfLangStrVar("UIString_1000268",[countGetMoney(0)]);
				var _tipLogic:MsgTipsLogic = MsgTipsLogic.getRes(ui.resultsBtn);
				var str:String = StaticIni.getSwfLangStrVar("94800",[countGetMoney(_multiLv),StaticIni.getSwfLangStr("CapitalType_0")]);
				_tipLogic.showInfo(str);
				SystemSender.getInstance().CustomMsgEx(
					CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_PRODUCTION_GAIN,[_type]);
				_model.dispatchEvent(new SoundEvent(SoundEvent.INDUSTRY_MONEY));
			}
			else
			{
				NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("UIString_1000259"))
			}

		}
		/**
		 * 刷新产业收益 
		 * @param e
		 * 
		 */		
		private function onshuaxinhandle(e:MouseEvent):void
		{
			if(_multiLv < 4)
			{
				SystemSender.getInstance().CustomMsgEx(
					CustomToServerFlag.CLIENT_CUSTOMMSG_PRODUCTION_MULTI_LV_UP,[_type]);
			}
			else
			{
				NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("UIString_1000281"))
			}
			LogSendLogic.getInstance().btnClickNumSend(22815);
		}
		
		private function onGroupClickHandle(e:MouseEvent):void
		{
			var friend:Record	= 	_model.scene.GetRecordEx("Friend");
			var	arr:Array		=	friend.recArr;		
			var index:int		=	(e.currentTarget as MovieClip)["Index"];
			//开始生产
			var friendName:WString	=	new WString(arr[0][0]);
			SystemSender.getInstance().CustomMsgEx(
				CustomToServerFlag.CLIENT_CUSTOMMSG_FRIEND_PRODUCTION_BEGIN_PRODUCE ,
				[6,index,friendName]);
		}
		
		private function onClickClose(e:NxWindowEvent):void
		{
			ui.hide();
			_timer.stop();	
		}
	}
}